﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace GraphDrawing
{
    class ValidateEdges
    {
        private readonly int _numberOfVertices;
        private readonly List<Edge> _edge;
        private List<Point> _vertices;

        public ValidateEdges(List<Edge> edgesList, ICollection verticesList)
        {
            _numberOfVertices = verticesList.Count;
            _edge = edgesList;
        }

        public bool IsValid()
        {
            _vertices = new List<Point>();

            foreach (var t in _edge)
            {
                _vertices.Add(t.GetPoint(0));
                _vertices.Add(t.GetPoint(1));
            }

            var verticesValidated = _vertices.ToList();

            for (int i = 0; i < verticesValidated.Count - 1; i++)
            {
                for (int j = 1; j < verticesValidated.Count; j++)
                {
                    if (i < verticesValidated.Count)
                    {
                        if (verticesValidated[i] == verticesValidated[j])
                        {
                            verticesValidated.RemoveAt(j);
                        }
                    } 
                }
            }

            //for (int i = 0; i < verticesValidated.Count; i++)
            //{
            //    if (i == 0)
            //    {
            //        verticesValidated.Add(vertices[0]);
            //    }

            //    for (int j = 0; j < vertices.Count; j++)
            //    {
            //        if (verticesValidated[i] != vertices[j])
            //        {
            //            verticesValidated.Add(vertices[j]);
            //        }
            //    }
            //}

            if (_numberOfVertices == verticesValidated.Count)
            {
                return true;
            }

            return false;
        }
    }
}
